package com.hotelvp.tonight.exception;

import android.content.Context;
import android.os.Process;
import java.io.PrintWriter;
import java.io.StringWriter;

public class DefaultExceptionHandler
  implements Thread.UncaughtExceptionHandler
{
  private Thread.UncaughtExceptionHandler defaultExceptionHandler;
  private GlobalExceptionInfo info;

  public DefaultExceptionHandler(GlobalExceptionInfo paramGlobalExceptionInfo, Context paramContext)
  {
    this.defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
    this.info = paramGlobalExceptionInfo;
  }

  public DefaultExceptionHandler(Thread.UncaughtExceptionHandler paramUncaughtExceptionHandler, GlobalExceptionInfo paramGlobalExceptionInfo)
  {
    this.defaultExceptionHandler = paramUncaughtExceptionHandler;
    this.info = paramGlobalExceptionInfo;
  }

  private void collectCrashExceptionInfo(Throwable paramThrowable)
  {
    StringWriter localStringWriter = new StringWriter();
    PrintWriter localPrintWriter = new PrintWriter(localStringWriter);
    paramThrowable.printStackTrace(localPrintWriter);
    this.info.stack_trace = localStringWriter.toString();
    localPrintWriter.close();
    sendToServer();
  }

  private boolean handleException(Throwable paramThrowable)
  {
    if (paramThrowable == null);
    while (true)
    {
      
      collectCrashExceptionInfo(paramThrowable);
      return true;
    }
  }

  // ERROR //
  private void sendToServer()
  {
    // Byte code:
    //   0: new 73	com/hotelvp/tonight/http/HttpClient
    //   3: dup
    //   4: invokespecial 74	com/hotelvp/tonight/http/HttpClient:<init>	()V
    //   7: astore_1
    //   8: invokestatic 80	com/hotelvp/tonight/App:instance	()Lcom/hotelvp/tonight/App;
    //   11: invokestatic 86	com/hotelvp/tonight/prefs/UserPrefs:get	(Landroid/content/Context;)Lcom/hotelvp/tonight/prefs/UserPrefs;
    //   14: astore 7
    //   16: new 88	java/lang/StringBuilder
    //   19: dup
    //   20: invokespecial 89	java/lang/StringBuilder:<init>	()V
    //   23: invokestatic 94	com/hotelvp/tonight/webservices/ServiceHost:getSaveCrashUrlV2	()Ljava/lang/String;
    //   26: invokevirtual 98	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   29: astore 8
    //   31: iconst_4
    //   32: anewarray 4	java/lang/Object
    //   35: astore 9
    //   37: aload 9
    //   39: iconst_0
    //   40: aload 7
    //   42: invokevirtual 101	com/hotelvp/tonight/prefs/UserPrefs:getClientCode	()Ljava/lang/String;
    //   45: invokestatic 107	android/net/Uri:encode	(Ljava/lang/String;)Ljava/lang/String;
    //   48: aastore
    //   49: aload 9
    //   51: iconst_1
    //   52: aload 7
    //   54: invokevirtual 110	com/hotelvp/tonight/prefs/UserPrefs:getUseCode	()Ljava/lang/String;
    //   57: invokestatic 107	android/net/Uri:encode	(Ljava/lang/String;)Ljava/lang/String;
    //   60: aastore
    //   61: aload 9
    //   63: iconst_2
    //   64: aload 7
    //   66: invokevirtual 113	com/hotelvp/tonight/prefs/UserPrefs:getVersionName	()Ljava/lang/String;
    //   69: invokestatic 107	android/net/Uri:encode	(Ljava/lang/String;)Ljava/lang/String;
    //   72: aastore
    //   73: aload 9
    //   75: iconst_3
    //   76: invokestatic 119	com/hotelvp/tonight/tools/Md5Encrypt:getInstance	()Lcom/hotelvp/tonight/tools/Md5Encrypt;
    //   79: aload_0
    //   80: getfield 26	com/hotelvp/tonight/exception/DefaultExceptionHandler:info	Lcom/hotelvp/tonight/exception/GlobalExceptionInfo;
    //   83: invokevirtual 123	com/hotelvp/tonight/tools/Md5Encrypt:getMd5	(Ljava/lang/Object;)Ljava/lang/String;
    //   86: invokestatic 107	android/net/Uri:encode	(Ljava/lang/String;)Ljava/lang/String;
    //   89: aastore
    //   90: aload_1
    //   91: aload 8
    //   93: ldc 125
    //   95: aload 9
    //   97: invokestatic 131	java/lang/String:format	(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    //   100: invokevirtual 98	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   103: invokevirtual 132	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   106: aload_0
    //   107: getfield 26	com/hotelvp/tonight/exception/DefaultExceptionHandler:info	Lcom/hotelvp/tonight/exception/GlobalExceptionInfo;
    //   110: invokevirtual 136	com/hotelvp/tonight/http/HttpClient:post	(Ljava/lang/String;Ljava/lang/Object;)V
    //   113: aload_1
    //   114: ldc 138
    //   116: ldc 140
    //   118: invokevirtual 144	com/hotelvp/tonight/http/HttpClient:addHeader	(Ljava/lang/String;Ljava/lang/String;)V
    //   121: aload_1
    //   122: ldc 146
    //   124: ldc 148
    //   126: invokevirtual 144	com/hotelvp/tonight/http/HttpClient:addHeader	(Ljava/lang/String;Ljava/lang/String;)V
    //   129: aload_1
    //   130: invokevirtual 151	com/hotelvp/tonight/http/HttpClient:execute	()V
    //   133: aload_1
    //   134: invokevirtual 155	com/hotelvp/tonight/http/HttpClient:getConnectionManager	()Lorg/apache/http/conn/ClientConnectionManager;
    //   137: invokeinterface 160 1 0
    //   142: return
    //   143: astore 6
    //   145: aload_1
    //   146: invokevirtual 155	com/hotelvp/tonight/http/HttpClient:getConnectionManager	()Lorg/apache/http/conn/ClientConnectionManager;
    //   149: invokeinterface 160 1 0
    //   154: goto -12 -> 142
    //   157: astore 5
    //   159: aload_1
    //   160: invokevirtual 155	com/hotelvp/tonight/http/HttpClient:getConnectionManager	()Lorg/apache/http/conn/ClientConnectionManager;
    //   163: invokeinterface 160 1 0
    //   168: goto -26 -> 142
    //   171: astore 4
    //   173: aload_1
    //   174: invokevirtual 155	com/hotelvp/tonight/http/HttpClient:getConnectionManager	()Lorg/apache/http/conn/ClientConnectionManager;
    //   177: invokeinterface 160 1 0
    //   182: goto -40 -> 142
    //   185: astore_3
    //   186: aload_1
    //   187: invokevirtual 155	com/hotelvp/tonight/http/HttpClient:getConnectionManager	()Lorg/apache/http/conn/ClientConnectionManager;
    //   190: invokeinterface 160 1 0
    //   195: goto -53 -> 142
    //   198: astore_2
    //   199: aload_1
    //   200: invokevirtual 155	com/hotelvp/tonight/http/HttpClient:getConnectionManager	()Lorg/apache/http/conn/ClientConnectionManager;
    //   203: invokeinterface 160 1 0
    //   208: aload_2
    //   209: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   8	133	143	org/codehaus/jackson/JsonGenerationException
    //   8	133	157	org/codehaus/jackson/map/JsonMappingException
    //   8	133	171	java/io/UnsupportedEncodingException
    //   8	133	185	java/io/IOException
    //   8	133	198	finally
  }

  public void uncaughtException(Thread paramThread, Throwable paramThrowable)
  {
    if ((!handleException(paramThrowable)) && (this.defaultExceptionHandler != null))
      this.defaultExceptionHandler.uncaughtException(paramThread, paramThrowable);
    while (true)
    {
      
      try
      {
        Thread.sleep(500L);
        Process.killProcess(Process.myPid());
        System.exit(10);
      }
      catch (InterruptedException localInterruptedException)
      {
        break;
      }
      return;
    }
  }
}